package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.User;
import com.itheima.reggie.entity.dto.LoginDto;
import com.itheima.reggie.mapper.UserMapper;
import com.itheima.reggie.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.boot.autoconfigure.security.SecurityProperties;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author:YZN
 * @date:2023/1/7
 * @description:
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User loginUser(String phone) {
        //判断该手机号是否注册
        User user = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getPhone, phone));
        if (user == null){
            //新用户
            user = new User();
            user.setPhone(phone);
            //status==1 代表账户正常使用
            user.setStatus(1);
            userMapper.insert(user);
        }
        //用户已存在

        return user;
    }
}
